<template>
<div>
<ul id="treeDemocompanytow" class="ztree" style="margin-top:0; width:468px; height: 300px;"></ul>
 <input type="hidden" id="company_id" value="">
</div>
</template>
<style  scoped>
 ul.ztree {
    margin-top: 10px;
    border: 1px solid #617775;
    background: #f0f6e4;
    width: 220px;
    height: 360px;
    overflow-y: auto;
    overflow-x: auto;
   
      
}
.ztree {
    margin: 0;
    padding: 5px;
    color: #333;
}
  ::-webkit-scrollbar {
            width: 6px;
            /*height: 6px;*/
        }
        /*正常情况下滑块的样式*/
      ::-webkit-scrollbar-thumb {
            background-color: rgba(0,0,0,.05);
            border-radius: 10px;
            -webkit-box-shadow: inset 1px 1px 0 rgba(0,0,0,.1);
        }
        /*鼠标悬浮在该类指向的控件上时滑块的样式*/
        :hover::-webkit-scrollbar-thumb {
            background-color: rgba(0,0,0,.2);
            border-radius: 10px;
            -webkit-box-shadow: inset 1px 1px 0 rgba(0,0,0,.1);
        }
        /*鼠标悬浮在滑块上时滑块的样式*/
       ::-webkit-scrollbar-thumb:hover {
            background-color: rgba(0,0,0,.4);
            -webkit-box-shadow: inset 1px 1px 0 rgba(0,0,0,.1);
        }
        /*正常时候的主干部分*/
        ::-webkit-scrollbar-track {
            border-radius: 10px;
            -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0);
            background-color: white;
        }
        /*鼠标悬浮在滚动条上的主干部分*/
        ::-webkit-scrollbar-track:hover {
            -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,.4);
            background-color: rgba(0,0,0,.01);
        }




/* @import '../../../../static/css/home/bootstrap.min.css';*/
 </style>
 <script>


var setting = {
			check: {
				enable: true,
				chkStyle: "radio",
				radioType: "all"
			},
			view: {
				dblClickExpand: false
			},
			data: {
				simpleData: {
					enable: true
				}
			},
			callback: {
			    onClick: onClicktow,
				onCheck: onClicktow
			}
        };




	function onClicktow(e, treeId, treeNode) {

       
            var zTree = $.fn.zTree.getZTreeObj("treeDemocompanytow"),
            
            check=zTree.checkNode(treeNode, true),

			nodes = zTree.getCheckedNodes(true),
				 v = "",d="";
			for (var i=0, l=nodes.length; i<l; i++) {
				v += nodes[i].name + ",";  d += nodes[i].id + ",";
			}
            if (v.length > 0 ) v = v.substring(0, v.length-1);
             if (d.length > 0 ) d = d.substring(0, d.length-1);

     
            hideMenutow();
            
            
            
             $("#company_name").val(v);
              $("body").bind("mousedown", onBodyDowntow);
            $("#company_id").val(d);  

             $("#myModal").find("span").eq(3).text("");
		}
function hideMenu() {
    $("#menuContent").fadeOut("fast");
    $("body").unbind("mousedown", onBodyDown);
}
function hideMenutow() {
    $("#menuContenttow").fadeOut("fast");
    $("body").unbind("mousedown", onBodyDown);
}
window.onBodyDowntow=function(event){
    if (!(event.target.id == "menuBtn" || event.target.id == "company_name" || event.target.id == "menuContenttow" || $(event.target).parents("#menuContenttow").length>0)) {
        hideMenutow();
    }
    //if (!(event.target.id == "menuBtn" || event.target.id == "citySel" || event.target.id == "menuContent" || $(event.target).parents("#menuContent").length>0)) {
  //      hideMenu();
   // }
}
$(document).ready(function(){ 
   // console.log(sessionStorage.getItem("coid"));
$("#company_name").click(function(){
//alert($("#company_id").val());
companytreetow();
});
});
window.companytreetow=function(){
  domain.ajaxUrl({
                method: 'POST',
                url: domain.testUrl+"/Threeinjection/basicmManagementpage/queryCoNameByCoid",
                data: {"sessionid":sessionStorage.getItem("sid"),"coid":sessionStorage.getItem("coid")},
                datatype:"JSON",
                success: function (response) {  
                   var obj = eval("("+response+")");
                   // console.log(response);
                    var newTree=$.fn.zTree.init($("#treeDemocompanytow"), setting, JSON.parse(obj.company));
var Nodes=newTree.getNodes();
var act=newTree.transformToArray(Nodes);
var MyNode;
var str='';
for(var i=0;i<act.length;i++)
{
if(act[i].id==$("#company_id").val()){
    newTree.selectNode(act[i],true);
newTree.checkNode(act[i],true);
}

//MyNode=newTree.getSelectedNodes();
//str+="'"+act[i].id+"',";
}
 console.log(str);
}
  });
}
 </script>
 